<?php
namespace app\tp\controller;
// use think\config;
// use think\Request;
use think\Cookie;
use think\Controller;     //这两个同时出现

class Index4 extends Controller  //这两个同时出现
{
   


public function index1()
	{
	//设置cookie.有效期3600秒
	echo "http://www.2018a.com/47.94.136.51/t5/public/note.php/tp/Index4/index1";
	Cookie::set('user_name3','TP-shop2',300);
	// 设置cookie 前缀为think_
    Cookie::set('user_name3','好几款',['prefix'=>'think_','expire'=>300]);
	$this->index2();
	}	


	public function index2(){
	echo'
	<hr/>
	<pre>
	头部有 
	 use think\Cookie; 就行

	cookie 设置：
	Cookie::set(\'user_name3\',\'TP-shop2\',300);

	// 设置cookie 前缀为think_
    Cookie::set(\'user_name3\',\'value\',[\'prefix\'=>\'think_\',\'expire\'=>300]);

	f12查看：
	在console 输入 document.cookie 即可
	</pre>
	';
	}

	public function index3(){
	echo Cookie::get('user_name3');
	echo  '<br/>获取有前缀的cookie 方法一：'.Cookie::get('user_name3','think_');
	echo  '<br/>获取有前缀的cookie 方法二：'.Cookie::get('think_user_name3');
	$this->index4();
	}
    public function index4(){
		echo'
		<hr/>
		<pre>
		读取 获得 cookie
		Cookie::get(\'user_name3\');
		 \'获取有前缀的cookie 方法一：\'.Cookie::get(\'user_name3\',\'think_\');
	     \'获取有前缀的cookie 方法二：\'.Cookie::get(\'think_user_name3\');
		</pre>
		';

	}
	public function index5(){
		echo '判断有没有user_name2:'.Cookie::has('user_name2');
		echo '<br/>判断有没有user_name3:'.Cookie::has('user_name3');
		$this->index6();
	}

	public function index6(){
	echo'
	<hr/>
	<pre>
	判断有没有user_name2  Cookie::has(\'user_name2\')
	判断有没有user_name3  Cookie::has(\'user_name3\')
	</pre>
	';
	}
}
